#include<bits/stdc++.h>
using namespace std;

int t, n, a[20], r[20], b[20], mx, sum, ans;
bool cl[20];

void f(int m, int rn, int bn){
	if(m > n){
		sum = 0;
		for(int i = 2; i < rn; i ++){
			if(a[r[i]] == a[r[i-1]]){
				sum += a[r[i-1]];
			}
		}
		for(int i = 2; i < bn; i ++){
			if(a[b[i]] == a[b[i-1]]){
				sum += a[b[i-1]];
			}
		}
		mx = max(mx, sum);
		return;
	}
	r[rn] = m;
	f(m+1, rn+1, bn);
	r[rn] = 0;
	b[bn] = m;
	f(m+1, rn, bn+1);
}

int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin >> t;
	while(t--){
		cin >> n;
		mx = 0, sum = 0, ans = 0;
		for(int i = 1; i <= n; i ++){
			cin >> a[i];
		}
		f(1, 1, 1);
		cout << mx << "\n";
	}
	return 0;
}
